<template>
<div class="parkingRecord">
    <!-- 搜索 -->
    <el-form   :model="searchData" class="searchForm">
      <el-form-item label="停车场名称">
        <el-input class="seech1" v-model="searchData.parkName"></el-input>
      </el-form-item>
      <el-form-item label="用户名称">
        <el-input class="seech1" v-model="searchData.userName"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input class="seech1" v-model="searchData.mobilePhone"></el-input>
      </el-form-item>
      <el-form-item label="车牌号">
        <el-input class="seech1" v-model="searchData.carCardNum"></el-input>
      </el-form-item>
      <el-form-item label="时长" class="form_type">
        <el-select class="seech2" v-model="searchData.ruleType">
          <el-option label="月卡" :value="0"></el-option>
          <el-option label="季卡" :value="1"></el-option>
          <el-option label="年卡" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号">
        <el-input class="seech1" v-model="searchData.id"></el-input>
      </el-form-item>
      <el-form-item label="购买时间" class="form_date">
        <el-date-picker :unlink-panels="true" v-model="searchData.buyTime" @change="getDate" type="daterange" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"  end-placeholder="结束日期">
        </el-date-picker>
        </el-form-item>
      <el-form-item class="form_type">
        <el-button type="primary" @click="searchTableData">搜索</el-button>
      </el-form-item>
    </el-form>


    <!-- 列表展示 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="订单编号" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="用户名称" align="center">
      </el-table-column>
      <el-table-column prop="mobilePhone" label="手机号码" align="center">
      </el-table-column>
      <el-table-column prop="carCardNum" label="车牌号" align="center">
      </el-table-column>
      <el-table-column prop="parkName" label="停车场" align="center">
      </el-table-column>
      <el-table-column prop="ruleName" label="月租卡名称" align="center">
      </el-table-column>
      <el-table-column label="时长" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.ruleType | ruleTypeFilter }}</span>
          </template>
      </el-table-column>
      <el-table-column prop="amount" label="价格" align="center">
      </el-table-column>
      <el-table-column prop="endTime" label="有效期" align="center">
        <template slot-scope="scope">
              <!-- <i class="el-icon-date"/> -->
              {{ scope.row.createTime | dateFilter }}
        </template>
      </el-table-column>
      <el-table-column prop="buyTime" label="购买时间" align="center">
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination layout="total, sizes, prev, pager, next, jumper" :total="tal" :hide-on-single-page="true" background :page-size="10" :page-sizes="[5,8,10]" align="center" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" style="margin-top:30px;">
    </el-pagination>

</div>
</template>

<script>
import axios from 'axios'
import qs from 'qs'
import { formatDate } from '@/utils/formatDate.js'

export default{
  name:'parkingRecord',
  filters: {
    ruleTypeFilter(ruleType) {
      if (ruleType == 0) {
        return '月卡'
      }
      if (ruleType == 1) {
        return '季卡'
      }
      if (ruleType == 2) {
        return '年卡'
      }
     },
      dateFilter(date) {
      // return formatDate(new Date(date), 'yyyy-MM-dd hh:mm:ss')
      if (date != null && date != '') {
        return formatDate(new Date(date), 'yyyy-MM-dd')
      } else {
        return ''
      }
     }
    },
  data(){
    return{
      tal:null,
      currentPage:1,
      searchData:{},
      tableData:[]
      }
  },
  mounted(){
    this.getTableData();//初始加载
  },
  methods:{
    searchTableData() {
      this.searchData.page = 1;
      this.getTableData();
    },
    //数据初始加载  条件搜索  分页数据修改  三者共用一个接口
    getTableData(){
      var userId = sessionStorage.getItem("userId");
      var token = sessionStorage.getItem("token");
      this.searchData.isLine = 1;
      this.searchData.userId = userId;
      this.searchData.token = token;
      axios({
        method:'post',
        url:'/api/bParkingleaserecord/selectRecordByManage',
        data:qs.stringify(this.searchData)
      }).then((res) => {
        this.tableData = res.data.data.list;
        this.tal = res.data.data.total;// 获取总条数
      })
    },
    //分页修改每页显示条数
    handleSizeChange(val){
      this.searchData.pageSize = val;
      this.getTableData();
    },
    //分页跳转页面
    handleCurrentChange(val){
      this.searchData.page = val;
      this.getTableData();
    },
    //获取正确日期
    getDate(date) {
      if (date != null) {
      this.searchData.buyStart = new Date(date[0])
      this.searchData.buyEnd = new Date(date[1])
      } else {
        this.searchData.buyStart = null
        this.searchData.buyEnd = null
        }
    },
    deleteRole(){

    }
  }
}
</script>

<style scoped>
.searchForm .el-form-item{
  display: inline-block;
  width: 220px;
}
.searchForm .form_type{
  width: 140px;
}
.searchForm .form_date{
  width: 420px;
}  
.parkingRecord{
  padding: 40px;
}
.btn{
  font-size: 12px;
  color:#7EC0EE;
  margin: 0 5px;
}
.btn:hover{
  cursor: pointer;
}
.seech1{
  width:130px;
}
.seech2{
  width:90px;
}




</style>

